/**
 * Created by damir.ismailov on 16/12/2014.
 */
package simple.controller {
	import com.samoiloff.framework.controller.AbstractController;

	import flash.events.Event;

	import simple.model.SimpleModel;

	import simple.view.SimpleView;

	public class SimpleRectanglePositionController extends AbstractController {

		private var _model : SimpleModel;
		private var _view : SimpleView;

		public function SimpleRectanglePositionController(view:SimpleView) {
			super(view);
			_view = view;
			_model = _view.model as SimpleModel;

			_model.addEventListener(SimpleModel.DISPLACEMENT_CHANGED, onDisplacementChanged);


			onDisplacementChanged();
		}


		override public function destroy() : void {
			_model.removeEventListener(SimpleModel.DISPLACEMENT_CHANGED, onDisplacementChanged);

			super.destroy();
		}

		private function onDisplacementChanged(event : Event = null) : void {
			_view.rectangle.x = _view.rectangle.y = _model.displacement ? 150 : 50;
		}
	}
}
